// AudioPlug library definitions
// 2010-05-12 <info@theater4all.nl> http://opensource.org/licenses/mit-license.php

#ifndef AudioPlug_h
#define AudioPlug_h

#include <WProgram.h>
#include <stdint.h>

#define MAXCHANNELS 16
#define MAXBOARDS  MAXCHANNELS/2

#define PORTLOW 0
#define PORTHIGH 1

#define MUTEON 1
#define MUTEOFF 0

#define TWOCHANNELS 2
#define OLDFOURCHANNELS 3
#define FOURCHANNELS 4

#define CLK_PIN  (basePortHigh ? 16 : 14)
#define DATA_PIN (basePortHigh ? 6 : 4) 
#define MUTE_PIN (basePortHigh ? 17 : 15)
#define CS_PIN   (basePortHigh ? 7 : 5) 

class AudioPlug {
protected:
	uint8_t boardType[MAXBOARDS];	
	uint8_t hardwareChannelPos[MAXCHANNELS];
	uint8_t VolumeBuffer[MAXCHANNELS];
	uint8_t nrAudioChannels;
	uint8_t nrBoards;
	uint8_t masterVolume;
	bool Mute;
	bool basePortHigh;
	void setChannelmap();
	void sendByte(uint8_t val);

	
public:
	inline AudioPlug (bool val) { basePortHigh = val;  init(); }
	void init();
	void sendVolumeData(void);
	void addBoard(uint8_t newBoardType);
	void setVolume(uint8_t channel, uint8_t value);
	uint8_t getVolume(uint8_t Channel);
	void setMute(bool value);
	bool getMute(void);
	void setMaster(uint8_t vol);
	uint8_t inline getMaster(void) { return masterVolume; };
	inline uint8_t nrChannels() { return (nrAudioChannels); }
	void showChannelMap();
	uint8_t dB2Byte (int dBValue);
	int byte2dB(uint8_t Value);	
};

#endif